/*  file: public.h  */

#ifndef PUBLIC_H
#define PUBLIC_H

#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

/* file and line number */
extern FILE *src;       /* point to source file */
extern int lineno;      /* source line number   */
extern FILE *my_test;   /* test file            */
extern FILE *syn_point;
extern FILE *vari_point;
extern FILE *tree_tab;
extern FILE *cfile_ptr;

/* bool type */
#ifndef true
#define true 1
#endif

#ifndef false 
#define false 0
#endif

/* NULL define */
#ifndef NULL
#define NULL  ((void*)0)      /* define NULL pointer */
#endif

/* token type define */
typedef enum
{
	ENDFILE, ERROR,
	IF, ELSE, INT, VOID, WHILE, MAIN, IN, OUT,
	ID, NUM,
	PLUS, MINUS, TIMES, DIVI, LS, LE, GT, GE, EQ, NE, ASSIGN, SEMI, COLO,
	LPARE, RPARE, LBRA, RBRA
}token_type;

/* variable table */
typedef struct tab
{
	int addr;                   /* variable's virtual address */
	char *name;                 /* variable's name            */
	struct tab *next;
}var_tab;
extern var_tab *tab_head;

/* syntax tree */
typedef enum
{
	stmt_b, exp_b
}base_kind;

typedef enum
{
	if_s, while_s, assign_s, in_s, out_s, null_s
}stmt_kind;

typedef enum
{
	op_e, const_e, id_e
}exp_kind;

typedef struct parser_tree_node
{
	struct parser_tree_node *child[3];
	struct parser_tree_node *next;
	int lineno;
	base_kind base;
	union 
	{
		stmt_kind stmt;
		exp_kind exp;
	}kind;
	union
	{
		token_type op;
		int value;
		char *name;
	}attribute;
}parser_tree;

#endif
